//
//  ViewController.m
//  UITableView
//
//  Created by yb on 16/3/4.
//  Copyright © 2016年 yb. All rights reserved.
//

#import "ViewController.h"

//遵循数据源协议
@interface ViewController ()<UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *TableView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //设置数据源
    self.TableView.dataSource = self;
    
}

//协议中方法的实现
//返回tableView的组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //设置tableView有3组;
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else if(section == 1)
    {
        return 2;
    }else
    {
        return 3;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //UItaCell；每一行的格子
    //indexPath；代表唯一 的一行
    //indexPath有两个属性：section，row
    //indexPath.section  ：获取到组号 0 1 2
    //indexPath.row :获取的行号
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
    cell.textLabel.text = @"hello World ！！！";
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            cell.textLabel.text = @"英语";
        }
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            cell.textLabel.text = @"语文";
        }else{
            cell.textLabel.text = @"历史";
        }
    }else if (indexPath.section == 2){
        if (indexPath.row == 0) {
            cell.textLabel.text = @"数学";
        }else if (indexPath.row == 1){
            cell.textLabel.text = @"生物";
        }else{
            cell.textLabel.text = @"化学";
        }
    }
    
    
    cell.imageView.image = [UIImage imageNamed:@"1.jpg"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
    
}
//给每一组添加头部标签
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return @"字母";
    }else if (section == 1){
        return @"汉字";
    }else{
        return @"数字";
    }
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return @"广泛的语言";
    }else if (section == 1){
        return @"中国文字博大精深";
    }else{
        return @"火星人的世界";
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
